package net.fpeg.kotlin.play

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test


internal class 补码Test {

    @Test
    fun asd() {
        assertEquals(补码("1101").sign(), -1)
        assertEquals(补码("0111").sign(), 1)
        assertEquals(补码("1101").算数右移().value, "1110")
        assertEquals(补码("1000").算数右移().value, "1100")
        assertEquals(补码("1000").算数左移().value, "0000")
        assertEquals(补码("1001011110").算数右移().value, "1100101111")
        assertEquals(补码("1001011110").算数左移().value, "0010111100")
    }

    @Test
    fun asddd() {
        val t1 = 补码乘法迭代组合(
            补码("110011"),
            补码("001101"),
            补码("000000010110"),
            补码乘法操作类型.移位减B,
            false
        ).补码乘法一步()
        val t2 = t1.补码乘法一步()
        val t3 = t2.补码乘法一步()
        val t4 = t3.补码乘法一步()
        val t5 = t4.补码乘法一步()
        val t6 = t5.补码乘法一步()
        assertEquals(
            t1.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=000110101011, 方法=仅移位, 终止步=false, 次数=1)"
        )
        assertEquals(
            t2.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=000011010101, 方法=移位加B, 终止步=false, 次数=2)"
        )
        assertEquals(
            t3.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=111011001010, 方法=移位减B, 终止步=false, 次数=3)"
        )
        assertEquals(
            t4.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=000100000101, 方法=移位加B, 终止步=true, 次数=4)"
        )
        assertEquals(
            t5.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=110111000101, 方法=终止, 终止步=false, 次数=5)"
        )
        assertEquals(
            t6.toString(),
            "补码乘法迭代组合(乘数=110011, 负乘数=001101, 被乘数=110111000101, 方法=终止, 终止步=false, 次数=6)"
        )


    }

    @Test
    fun a() {
        println(补码("10011").补码乘法演示(补码("01011")))
    }
}